package xyz.eden.boot.core.exception;

import java.util.Objects;

/**
 * 异常数据工具类
 *
 * @author gavin
 * @version 1.0
 * @descriptor
 * @date 2022/12/6 17:01
 */
public class ExceptionDataUtils {

    public static <T> T getData(ExceptionData exceptionData, Class<T> clazz) {
        if (Objects.isNull(exceptionData)) {
            return null;
        }

        if (Objects.isNull(clazz)) {
            return null;
        }

        try {
            Object data = exceptionData.getData();
            if (Objects.isNull(data)) {
                return null;
            }
            return clazz.cast(data);
        } catch (Exception e) {
            return null;
        }
    }
}